Analytics
Build and run custom queries to analyze your application data.
Overview
Analytics provides a query builder interface to create custom SQL queries against your application data. Build reports, analyze trends, and export data for further analysis.
Concepts
Query
A saved SQL query that can be executed to retrieve data from your app's database tables.
Connection
A database connection or secret that provides credentials for query execution.
Parameters
Dynamic values that can be passed to queries at runtime, allowing reusable queries with different inputs.
View Queries
- Navigate to your App in the Dashboard.
- Click Analytics in the sidebar.
- View all saved queries with:
- Query Name: Display name
- Description: Query purpose
- Created: When the query was created
- Last Run: Most recent execution
Create a Query
- Navigate to Analytics in your app.
- Click Create Query.
- Fill in query details:
- Name: Descriptive query name
- Description: Purpose of the query
- Connection: Select data connection/secret
- Write your SQL query.
- Click Save.
Query Editor
The query editor provides a full-featured SQL editing environment:
Writing Queries
SELECT
user_id,
COUNT(*) as order_count,
SUM(total_amount) as total_spent
FROM orders
WHERE created_at > :start_date
GROUP BY user_id
ORDER BY total_spent DESC
LIMIT 100;
Using Parameters
Define parameters with colon syntax:
SELECT * FROM products
WHERE category = :category
AND price <= :max_price;
Parameters appear in the parameter form when executing.
Execute a Query
- Navigate to the query.
- Fill in any required parameters.
- Click Execute.
- View results in the data table:
- Column headers from query
- Result rows
- Row count
View Query Results
Results are displayed in a DataTable with:
| Feature | Description |
|---|---|
| Sorting | Click column headers to sort |
| Pagination | Navigate through large result sets |
| Column Resize | Adjust column widths |
Export Results
Export query results to files:
Export to CSV
- Run the query.
- Click Export.
- Select CSV.
- Download the file.
Export to Excel
- Run the query.
- Click Export.
- Select Excel.
- Download the file.
Edit a Query
- Navigate to Analytics in your app.
- Click on the query to open it.
- Modify the SQL or settings.
- Click Save.
Delete a Query
- Navigate to Analytics in your app.
- Click the Delete (trash) icon on the query.
- Confirm deletion.
Data Connections
Select Connection
Queries run against a specific data connection:
- When creating/editing a query, select Connection.
- Choose from available connections or secrets.
- The query will use those credentials to connect.
Available Connections
- Default: Your app's primary database
- Secrets: External databases configured in site secrets
Query Examples
Count Records
SELECT COUNT(*) as total_users FROM users;
Aggregate Data
SELECT
DATE(created_at) as date,
COUNT(*) as signups
FROM users
WHERE created_at >= :start_date
GROUP BY DATE(created_at)
ORDER BY date DESC;
Join Tables
SELECT
u.name,
u.email,
COUNT(o.id) as orders
FROM users u
LEFT JOIN orders o ON u.id = o.user_id
GROUP BY u.id, u.name, u.email
ORDER BY orders DESC;
Parameterized Query
SELECT * FROM products
WHERE category = :category
AND status = 'active'
ORDER BY name;
Configuration
Query Fields
| Field | Description | Required |
|---|---|---|
| Name | Display name | Yes |
| Description | Query purpose | No |
| Connection | Data connection | Yes |
| SQL | Query text | Yes |
Limits
| Resource | Limit |
|---|---|
| Queries per app | 100 |
| Result rows | 10,000 |
| Query timeout | 30 seconds |
| Export size | 50 MB |
Need higher limits? Contact support to discuss your requirements.
Troubleshooting
Query returns error
Problem: Query execution fails with a SQL error.
Solution:
- Check SQL syntax is correct.
- Verify table and column names exist.
- Ensure parameter placeholders match inputs.
- Check the connection has access to the tables.
Query times out
Problem: Query takes too long and times out.
Solution:
- Add LIMIT clause to reduce result size.
- Add indexes on filtered columns.
- Optimize the query with smaller date ranges.
- Break into multiple smaller queries.
No results returned
Problem: Query returns empty results.
Solution:
- Verify the WHERE conditions match data.
- Check parameter values are correct.
- Test with broader conditions first.
- Confirm data exists in the tables.
Related
Last Updated: January 2025